﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using VVA.Data.Service;
using VVA.Website.UI.Helper;
using VVA.Website.UI.Models;

namespace VVA.Website.UI.Controllers
{
    public class ProductController : BaseController
    {
        //
        // GET: /Product/
        [OutputCache(Duration = 360, VaryByParam = "none")]
        public ActionResult Index()
        {
            var service = new TaxonomyService();
            var model = service.GetAll("Product", Culture);
            return View(model);
        }

        [OutputCache(Duration = 360, VaryByParam = "slug")]
        public ActionResult Detail(string slug)
        {
            var service = new ProductService();
            var model = new ProductDetailModel();
            var lst = service.GetAllByTaxonomySlug(slug, Culture);

            model.Products = lst;
            
            if (lst.Count() > 0)
            {                
                model.TaxonomyName = lst.FirstOrDefault().TaxonomyName;
            }
            
            return View(model);
        }

        [OutputCache(Duration = 360, VaryByParam = "slug")]
        public ActionResult Read(string slug)
        {
            var service = new ProductService();
            
            var lst = service.GetBySlug(slug);

            return View(lst);
        }
    }
}
